package cn.lds.healthj377.interceptor;

import cn.lds.healthj377.domain.User;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.Objects;

public class AdminRoleInterceptor implements HandlerInterceptor {


  @Override
  public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
    throws Exception {
    HttpSession session = request.getSession();

    User loginUser = (User) session.getAttribute("loginUser");

    if (loginUser.getRoleId() != 3){
      request.setAttribute("exceptionErr.msg","无权访问");
      request.getRequestDispatcher("/WEB-INF/views/error.jsp").forward(request,response);
    }
    return true;
  }

}